import { useState, useRef } from "react";

export const useGetState = (initVal) => {
  const [state, setState] = useState(initVal);
  const ref = useRef(initVal);
  const setStateCopy = (newVal) => {
    setState(newVal);
    ref.current = newVal;
  };
  const getState = () => ref.current;
  return [state, setStateCopy, getState];
};
